//
//  UIButton+Extension.swift
//  SinaWeiBo
//
//  Created by tuyue on 16/3/12.
//  Copyright © 2016年 xueyang.co.ltd. All rights reserved.
//

import UIKit

extension UIButton{
/**封装Button*/
    class func buttonWithImage(imageName:String? ,backImageName:String? ) -> UIButton{
        
     let btn = UIButton()
        if imageName != nil {
            btn.setImage(UIImage(named: imageName!), forState: .Normal)
            btn.setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
        }
        
        if backImageName != nil {
            btn.setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            btn.setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
       
       /**自适应大小*/
        btn.sizeToFit()
        return btn
    }
    
    class func buttonWithTitle(title: String,backImageName: String?,titleColor:UIColor,fontSize:CGFloat,imageName:String? = nil) -> UIButton{
             
         let btn = UIButton()
        
    
        btn.setBackgroundImage(UIImage(named: backImageName!),forState: .Normal)
    
        btn.setImage(UIImage(named: imageName!), forState: .Normal)
        
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(titleColor, forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        btn.sizeToFit()
        return btn
        
    }

}